home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / OvalsDoodadd-1.2-c / Ovals.c < prev    next >
Encoding:
Text File  |  1994-12-04  |  19.8 KB  |  646 lines  |  [TEXT/MMCC]

  1. //•-----------------------------------------------------------------------•//
  2. //• Ovals.c                                                                  •//
  3. //• Ploppyright (P) 1993 Kenneth A. Long.  No rights reserved.              •//
  4. //•-----------------------------------------------------------------------•//
  5.  
  6. //•-----------------------------------------------------------------------•//
  7. //• I got the oval thing from an old public domain .c file by Greg Corson •//
  8. //• (which I've included, so you can see all the wrong character case).      •//
  9. //• The .c file was called "Display.c" and was merely a program to open a •//
  10. //• text file and display the contents.  The oval part was kinda cool, so •//
  11. //• put it in here by itself, stripped all the extra trash, added some      •//
  12. //• controls from "EarthPlot 3.0" and modified them for this.  I have      •//
  13. //• learned a few things in making this thing work.  Maybe you can, too.  •//
  14. //•-----------------------------------------------------------------------•//
  15. //• Be sure to try changes, as in the "Ovalize" routine suggestions.      •//
  16. //•-----------------------------------------------------------------------•//
  17.  
  18. //•-----------------------------------------------------------------------•//
  19. //• -------------------------------ENJOY!-------------------------------- •//
  20. //•-----------------------------------------------------------------------•//
  21.  
  22. #include <packages.h>
  23.  
  24. //•-----------------------------------------------------------------------•//
  25. //• Raiders of the Lost EarthPlot source.
  26. //•-----------------------------------------------------------------------•//
  27.  
  28. short    npictButton, nbitmapButton, nintButton, nfpButton,
  29.         nhiddenlinesBox, nlnlBox, nsquareBox;
  30.     
  31. long    backgroundC, earthbackgroundC, earthoutlineC, ovalTotalC,
  32.         verticalC, landC;
  33.  
  34. Rect    H_OvalTotalBarRect, V_OvalTotalBarRect, H_OvalTotalDataRect,
  35.         V_OvalTotalDataRect, horizontalBarRect, horizontalDataRect,
  36.         verticalBarRect, verticalDataRect, controlsRect, buttonRect;
  37.  
  38. ControlHandle    hOvalTotalBar, vOvalTotalBar, verticalBar, horizontalBar,
  39.                 goButton;
  40.  
  41. enum {
  42.     appleID = 1, 
  43.     fileID,             //• Must be "2" huh?
  44.     editID              //• Must be "3" (duh).
  45. };
  46.     
  47. #define    ours(w) ((theWindow != NULL) && (w == theWindow))    //• From MiniEdit.
  48.  
  49. MenuHandle        appleMenu, fileMenu, editMenu;
  50.  
  51. Rect            dragRect, ovalRect, totalBarRect, vOffBarRect, 
  52.                 hOffBarRect, controlsRect;
  53.                 
  54. Boolean            doneFlag, temp, Resized;
  55. EventRecord      myEvent;
  56. short            code, refNum;
  57. WindowRecord     wRecord;
  58. WindowPtr        theWindow, whichWindow;
  59. GrafPtr            tempPort;
  60. short            theMenu, theItem,
  61.                 fileOpen, width, fd1,
  62.                 numH_Ovals, numV_Ovals, hOffset, vOffset,
  63.                 j, i;
  64.  
  65. long            count;
  66. char            tempBuf[32];
  67. Rect            windowBounds = { 0, 0, 384, 512 };    //• Our window size.
  68. Point            thePoint;
  69.  
  70. //•-----------------------------------------------------------------------•//
  71.  
  72. //•-----------------------------------------------------------------------•//
  73. //• HandleMenu (theMenu, theItem)---this subroutine processes commands      •//
  74. //• from the menu bar.                                                      •//
  75. //• theMenu is the menu ID, theItem is the item number in the menu          •//
  76. //•-----------------------------------------------------------------------•//
  77.  
  78.  
  79. DoSplash ()
  80. {
  81.     long ticks;
  82.     
  83.     DrawThemStrangs ();        //• The window is already up, so we draw in it.
  84.     Delay (240L, &ticks);    //• 60 ticks per second = 4 seconds of fame.
  85.     EraseRect (&ovalRect);    //• Dump it and move on.
  86.     AddControls ();            //• We didn't want them spoiling our bragging.
  87.     DrawControlLabels ();    //• Send the names to Chicago!
  88.     
  89. }
  90.  
  91. //•-----------------------------------------------------------------------•//
  92.  
  93. HandleMenu (theMenu, theItem)
  94. short theMenu, theItem;
  95. {
  96.     char name [256];
  97.     
  98.     switch (theMenu)
  99.     {
  100.         case appleID:                //• Mouse down in apple menu.
  101.             if (theItem == 1)        //• The "About" item.
  102.             {
  103.                 DrawThemStrangs ();
  104.             }
  105.             else
  106.                 {
  107.                     GetItem (appleMenu, theItem, (StringPtr) name);
  108.                     refNum = OpenDeskAcc ((StringPtr) name);
  109.                     SetPort (theWindow);
  110.             }
  111.         break;
  112.         case fileID:    //• Mouse down in file menu.
  113.             switch (theItem)
  114.             {
  115.                 case 1:        //• Open file?  For what? We're not using it.
  116.                 case 2:        //• Close file. For what? We're not using it.
  117.                 break;
  118.             
  119.                 case 3:        //• Quit.
  120.                     doneFlag = true;    //• Yep!  When we quit, we're done.
  121.                 break;
  122.             }
  123.         break;
  124.             
  125.         case editID:                    //• Process system edit events.
  126.             SystemEdit (theItem-1);        
  127.         break;
  128.     }
  129.     HiliteMenu (0);
  130. }
  131. //•-----------------------------------------------------------------------•//
  132. //• SetUpMenus ()    "Hot wires" them in, rather that a resource used.
  133. //• This subroutine sets up menu bar and reads in desk accessory menu
  134. //•-----------------------------------------------------------------------•//
  135.  
  136. SetUpMenus ()
  137. {
  138.     InsertMenu (appleMenu = NewMenu (appleID, "\p\024"), 0);
  139.     InsertMenu (fileMenu = NewMenu (fileID, "\pFile"), 0);
  140.     InsertMenu (editMenu = NewMenu (editID, "\pEdit"), 0);
  141.     DrawMenuBar ();
  142.     AppendMenu (appleMenu, "\pAbout Oval Doodadd…");
  143.     AddResMenu (appleMenu, 'DRVR');
  144.     AppendMenu (fileMenu, "\pWhy?;What?;Quit/Q");
  145.     AppendMenu (editMenu, "\pUndo/Z; (-;Cut/X;Copy/C;Paste/V;Clear");
  146. }
  147.  
  148. //•-----------------------------------------------------------------------•//
  149.  
  150. ControlsDataUpdate ()
  151. {
  152.     char s [64];
  153.  
  154.     MoveTo (72, 350);                                //• 72 over, 350 down.
  155.     
  156.     //• Change the value stored in a short (integer) to a string.
  157.     //• That is, turn the value into a "picture" of the value.
  158.     //• And get that value from whatever the control is set at.
  159.     NumToString (GetCtlValue (hOvalTotalBar), (StringPtr) s);
  160.     
  161.     //• Make sure there is nothing in the place we'll draw the value picture.
  162.     EraseRect (&H_OvalTotalDataRect);
  163.     
  164.     //• Draw a "picture" of the value gotten from the control.
  165.     DrawString ((StringPtr) s);
  166.  
  167.     //• Do it all agoin someplace else.
  168.     MoveTo (182, 350);
  169.     NumToString (GetCtlValue (vOvalTotalBar), (StringPtr) s);
  170.     EraseRect (&V_OvalTotalDataRect);
  171.     DrawString ((StringPtr) s);
  172.     
  173.     MoveTo (292, 350);
  174.     NumToString (GetCtlValue (verticalBar), (StringPtr) s);
  175.     EraseRect (&verticalDataRect);
  176.     DrawString ((StringPtr) s);
  177.     
  178.     MoveTo (412, 350);
  179.     NumToString (GetCtlValue (horizontalBar), (StringPtr) s);
  180.     EraseRect (&horizontalDataRect);
  181.     DrawString ((StringPtr) s);
  182. }
  183.  
  184. //•-----------------------------------------------------------------------•//
  185.  
  186. InitRectangles ()
  187. {
  188.     SetRect (&ovalRect, 6, 25, 507, 320);    //• Shortened for control space.
  189.     
  190.     SetRect (&controlsRect, 0, 320, 512, 384);    //• Just for a separate
  191.                                                 //• area for the controls.
  192.                                                 //• Not really needed/used.
  193.  
  194.     SetRect (&buttonRect,      440, 354, 500, 374);    //• Our Draw Button.
  195.  
  196.     SetRect (&H_OvalTotalBarRect,      10, 358, 100, 374);    //• Scroll Bars.
  197.     SetRect (&V_OvalTotalBarRect,     110, 358, 210, 374);
  198.     SetRect (&verticalBarRect,         220, 358, 320, 374);
  199.     SetRect (&horizontalBarRect,     330, 358, 430, 374);
  200.  
  201.  
  202.     SetRect (&H_OvalTotalDataRect,      72, 330, 102, 350);    //• For data.
  203.     SetRect (&V_OvalTotalDataRect,     182, 330, 212, 350);    //• Or "labels."
  204.     SetRect (&verticalDataRect,     292, 330, 322, 350);
  205.     SetRect (&horizontalDataRect,     412, 330, 432, 350);
  206. }
  207.  
  208. //•-----------------------------------------------------------------------•//
  209.  
  210. DrawControlLabels ()
  211. {
  212.     GrafPtr    thePort;
  213.     GetPort (&thePort);
  214.  
  215.     DrawControls (thePort);            //• Freshen up the controls, whether
  216.                                     //• neede or not.
  217.     TextFont (0);                    //• Make sure we're in Chicago.
  218.     MoveTo (10, 350);                //• Go here.
  219.     DrawString ("\pH # Ovals:");    //• Draw this profound statement.
  220.     MoveTo (110, 350);                //• Move.
  221.     DrawString ("\pV # Ovals:");    //• Do.
  222.     MoveTo (220, 350);                //• Etcetera.
  223.     DrawString ("\pV Offset:");
  224.     MoveTo (330, 350);
  225.     DrawString ("\pH Offset:");
  226.     
  227.     ControlsDataUpdate ();            //• Make the output track, in case it
  228. }                                    //• was messed up.
  229.  
  230. //•-----------------------------------------------------------------------•//
  231.  
  232. Track (ControlHandle theControl, short partCode)
  233. {
  234.  
  235.     short        i, step;
  236.     long    wait;
  237.     long    waited;
  238.     char    s [128];
  239.  
  240.     wait = 5; //• ticks.
  241.  
  242.     if (partCode == 0)                 //• If we ain't clickin' then don't
  243.         return;                        //• hang around here!
  244.     
  245.     switch (partCode)                 //• If we be clickin' then get to
  246.     {                                //• switchin'!
  247.         case inUpButton:
  248.             step = -1;                //• Pick it down by 1.
  249.         break;
  250.         
  251.         case inDownButton:
  252.             step = 1;                //• Bump it up 1.
  253.         break;
  254.         
  255.         case inPageUp:
  256.             step = -10;                //• Subtracts 10 increments.
  257.         break;
  258.         
  259.         case inPageDown:
  260.             step = 10;                //• Adds up 10 increments.
  261.         break;
  262.     
  263.         case inButton:
  264.             EraseRect (&ovalRect);    //• In case you hit the button, it draws.
  265.             Ovalize ();                //• That's handy!
  266.         break;
  267.     }
  268.     //• Whichever one of the cases switched to, make it so, Number One, ...
  269.     i = GetCtlValue (theControl) + step;    //• by assigning the value of
  270.                                             //• the control's setting to "i"
  271.                                             //• AND the "step" amount +/-.
  272.     //• Handle the individual controls.
  273.     if (*theControl == *hOvalTotalBar)
  274.     {
  275.         if (i > 148)         //• Whatever "i" is, it's 0 to 148.
  276.             i = 148;
  277.         if (i < 0) 
  278.             i = 0;
  279.  
  280.         SetCtlValue (theControl, i);    //• Set that control to what it IS.
  281.  
  282.         //• Wibe off the drawing surface.
  283.         EraseRect (&H_OvalTotalDataRect);
  284.         
  285.         MoveTo (72, 350);                //• Go here.
  286.         
  287.         //• Same as before.
  288.         NumToString (GetCtlValue (hOvalTotalBar), (StringPtr) s);
  289.         DrawString ((StringPtr) s);
  290.         Delay (wait, &waited);
  291.     }
  292.     //• And so on..................................!
  293.     if (*theControl == *vOvalTotalBar) 
  294.     {
  295.         if (i > 251) 
  296.             i = 251;
  297.         if (i <  0) 
  298.             i = 0;
  299.  
  300.         SetCtlValue (theControl, i);
  301.  
  302.         EraseRect (&V_OvalTotalDataRect);
  303.         MoveTo (182, 350);
  304.         NumToString (GetCtlValue (vOvalTotalBar), (StringPtr) s);
  305.         DrawString ((StringPtr) s);
  306.         Delay (wait, &waited);
  307.     }
  308.  
  309.     if (*theControl == *verticalBar) 
  310.     {
  311.         if (i > 50) 
  312.             i = 50;
  313.         if (i <  0) 
  314.             i = 0;
  315.  
  316.         SetCtlValue (theControl, i);
  317.  
  318.         EraseRect (&verticalDataRect);
  319.         MoveTo (292, 350);
  320.         NumToString (GetCtlValue (verticalBar), (StringPtr) s);
  321.         DrawString ((StringPtr) s);
  322.         Delay (wait, &waited);
  323.     }
  324.     
  325.     if (*theControl == *horizontalBar) 
  326.     {
  327.         if (i > 49)     //• If the counter's more than 49,
  328.             i = 49;        //• then the count is 49.
  329.         if (i <  0)     //• Same for less than 49.
  330.             i = 0;        //• But the it's zero.
  331.  
  332.         SetCtlValue (theControl, i);
  333.  
  334.         EraseRect (&horizontalDataRect);
  335.         MoveTo (412, 350);
  336.         NumToString (GetCtlValue (horizontalBar), (StringPtr) s);
  337.         DrawString ((StringPtr) s);
  338.         Delay (wait, &waited);
  339.     }
  340.     
  341.     if (*theControl == *goButton)        //• If we click in the "Draw"
  342.     {                                    //• button, we DRAW!!!!!!!!
  343.         EraseRect (&ovalRect);            //• (duh)
  344.         Ovalize ();
  345.     }
  346. }
  347.  
  348. //•-----------------------------------------------------------------------•//
  349. //• It's the content of the controls we're interested in.                  •//
  350. //•-----------------------------------------------------------------------•//
  351.  
  352. DoContent(WindowPtr theWindow, EventRecord *theEvent)
  353. {    
  354.     ControlHandle    theControl;
  355.     short                partCode;
  356.     char            s [100];
  357.     WindowPtr myWindow;
  358.  
  359.     partCode = FindControl (theEvent->where, theWindow, &theControl);
  360.  
  361.     if (partCode) 
  362.     {
  363.         switch (partCode) 
  364.         {        
  365.             case inUpButton:
  366.             case inDownButton:
  367.             case inPageUp:
  368.             case inPageDown:
  369.                 partCode = TrackControl (theControl, theEvent->where, 0L);
  370.                 Track (theControl, partCode);
  371.                 ControlsDataUpdate ();
  372.             break;
  373.             
  374.             case inThumb:
  375.                 partCode = TrackControl (theControl, theEvent->where, 0L);
  376.                 ControlsDataUpdate ();
  377.             break;
  378.             
  379.             case inButton:        //• Not this again!
  380.                 partCode = TrackControl (theControl, theEvent->where, 0L);
  381.                 EraseRect (&ovalRect);
  382.                 Ovalize ();
  383.             break;
  384.         }
  385.     }
  386. }
  387.  
  388. //•-----------------------------------------------------------------------•//
  389.  
  390. Ovalize ()            //• Get yer MoJo workin'!
  391. {
  392.     Rect tempRect;
  393.  
  394.     SetPort (theWindow);
  395.     HiliteWindow (theWindow, false);
  396.     
  397.         //• The # of ovals is the same as the control value the user set.
  398.         numH_Ovals = GetCtlValue (hOvalTotalBar);    //• "=" means "is".
  399.         numV_Ovals = GetCtlValue (vOvalTotalBar);    
  400.         
  401.         //• The oval offset is the same as the control value the user set.
  402.         vOffset    = GetCtlValue (verticalBar);
  403.         hOffset    = GetCtlValue (horizontalBar);
  404.  
  405.         BlockMove (&ovalRect, &tempRect, (long)sizeof ovalRect);
  406.         for (j = 0; j < numV_Ovals; j++)    //• Change vertical ovals here.
  407.         {
  408.             FrameOval (&tempRect);        //• Comment this line out and then
  409. //•         FrameRect (&tempRect);        //• uncomment this line for square.
  410.             InsetRect (&tempRect, vOffset, 0);
  411.         }
  412.         BlockMove (&ovalRect, &tempRect, (long)sizeof ovalRect);
  413.         for (j = 0; j < numH_Ovals; j++)
  414.         {
  415.             FrameOval (&tempRect);        //• Comment this line out and then
  416. //•         FrameRect (&tempRect);        //• uncomment this line for square.
  417.             InsetRect (&tempRect, 0, hOffset);
  418.         }
  419. }
  420.  
  421. //•-----------------------------------------------------------------------•//
  422.  
  423. DoInitManagers ()                    //• Hire these guys to manage stuff.
  424. {    
  425.     InitGraf (&qd.thePort);
  426.     InitFonts ();
  427.     FlushEvents (everyEvent, 0);
  428.     InitWindows ();
  429.     InitMenus ();
  430.     TEInit ();
  431.     InitDialogs (0L);
  432.     InitCursor ();
  433. }
  434.  
  435. //•-----------------------------------------------------------------------•//
  436. //• The window is hot-wired in, too.  Why mess with a resource for this 
  437. //• little thing?
  438. //•-----------------------------------------------------------------------•//
  439.  
  440. SetUpWindow ()
  441. {
  442.     //• Setup the drag Rectangle so part of the window will always be visible.
  443.     dragRect = qd.screenBits.bounds;
  444.     
  445.     //• Create the window and set the current port to the window port.
  446.     theWindow = NewWindow (&wRecord, &windowBounds, "\p", true, 2, 
  447.              (WindowPtr)-1L, false, 0L);
  448.     SetPort (theWindow);
  449.     
  450.     //• get the Rectangle for the current window and put it in ovalRect.
  451.     BlockMove (&qd.thePort->portRect, &ovalRect, (long) sizeof ovalRect);
  452.     width = ovalRect.right  - ovalRect.left;
  453.         
  454.     InitRectangles ();        //• Now that we have a window, put things in it.
  455.  
  456. }
  457. //•-----------------------------------------------------------------------•//
  458.  
  459. AddControls ()
  460. {
  461.     //• A new button.
  462.     goButton    = NewControl (theWindow, &buttonRect, 
  463.                                 "\pDraw", true,  0L, 0L, 0L, 0, 0L);    
  464.     
  465.     //• And 4 new scroll bars.
  466.     hOvalTotalBar    = NewControl (theWindow, &H_OvalTotalBarRect, 
  467.                                  (StringPtr) "", true,  1, 1, 148, 16, 0L);
  468.                                             
  469.     horizontalBar    = NewControl (theWindow, &horizontalBarRect,  
  470.                                  (StringPtr) "", true,  1, 1, 49, 16, 0L);    
  471.  
  472.     vOvalTotalBar    = NewControl (theWindow, &V_OvalTotalBarRect, 
  473.                                  (StringPtr) "", true,  1, 1, 251, 16, 0L);
  474.                                             
  475.     verticalBar        = NewControl (theWindow, &verticalBarRect,      
  476.                                  (StringPtr) "", true,  1, 1, 50, 16, 0L);    
  477. }
  478.  
  479. //•-----------------------------------------------------------------------•//
  480. //• Centers the strings in the window.                                      •//
  481. //•-----------------------------------------------------------------------•//
  482.  
  483. Center (char *str)
  484. {
  485.     //• Move what?  The pen to draw with.  Notice we don't use a pencil?
  486.     //• "right" and "left" and "width" imply horizontal.
  487.     //• Width is assigned "ovalRect.right" (507) minus "ovalRect.left" (6).
  488.     //• That makes "width" 501.
  489.     //• 501 minus the width of "str" leaves us with an amount.
  490.     //• Then the "0" means we are at the top - or vertical 0.
  491.     //• So we are at the top and 501 minus the StringWidth, divided by 2
  492.     //• from the left.  If the StringWidth is 101, we're at 200.  Dig?
  493.     Move (((width - StringWidth ((StringPtr) str)) / 2), 0);
  494.     
  495.     DrawString ((StringPtr) str);            //• We draw the string there.
  496.     
  497.     //• Am I supposed to explain this one, too?
  498.     Move (-(theWindow->pnLoc.h), (theWindow->txSize) + 2);
  499. }
  500.  
  501. //•-----------------------------------------------------------------------•//
  502.  
  503. DrawThemStrangs ()
  504. {
  505.     EraseRect (&ovalRect);
  506.     TextFont (courier);        //• Could use a procID number for the font.
  507.     TextFace (outline);        //• Without this fragment, it would be plain.
  508.     TextSize (24);            //• Big ol' typewriter font!
  509.     MoveTo (ovalRect.left -10, ovalRect.top + 20);    //• Start at down 20.
  510.     Center ((char*) "\pOval Drawing Doodadd");    //• Did I spell "doodadd right?
  511.                                                 //• Always take a "\p" first!
  512.     Move (0, 10);                                //• MW C likes (char*).
  513.     TextFont (monaco);
  514.     TextSize (9);
  515.     TextFace (bold);
  516.     Center ((char*) "\pPublic Domain (P) 1993 by Kenneth A. Long");
  517.     
  518.     Move (0, 10);
  519.     TextFont (courier);    
  520.     TextFace (outline);    
  521.     TextSize (14);            //• 5 points bigger in size.
  522.     Center ((char*) "\pitty bitty bytes™");
  523.     
  524.     TextFont (monaco);        //• Change of font duly noted.
  525.     TextFace (bold);        //• The "brazen" style!
  526.     TextSize (9);            //• The incredible shrinking font.
  527.     Center ((char*) "\pkenlong@netcom.com");    //• I know this guy!
  528.     
  529.     TextFace (0);            //• Zero = systemFont = Chicago (on my LC).
  530.     Move (0, 20);            //• Drop that pen down 20 points.
  531.     
  532.     Center ((char*) "\pGleaned from a file display program from 1985 by Greg Corson.");
  533.     Center ((char*) "\pYou should NOT try sell this for profit.  Nobody would buy it.");
  534.  
  535.     TextFont (courier);        //• Font stays the same until you say different.
  536.     TextSize (10);            //• Courier looks bad in 9.
  537.     Move (0, 10);            //• Drop down 10 points.
  538.     Center ((char*) "\p\"I Think, therefore I 'C'.\"  Ain't Think C™ v.5.0.4 great!");
  539.     Center ((char*) "\p(But HEY!  Code Warrior's pretty cool, too!)");
  540.  
  541.     Move (0, 10);            //• Drop down 10 points.
  542.     TextFont (monaco);        //• Back to Monaco (stay out of the casinos!).
  543.     TextSize (9);            //• Shrink back to 9 for this font.
  544.     Center ((char*) "\pThis program was made to help beginning programmers learn things.");
  545.     Center ((char*) "\pFeel free to give this program away to all your friends.");
  546.     Center ((char*) "\pPost it on your local board and otherwise distribute it freely");
  547.     Center ((char*) "\pThe oval drawing was the least common program feature of Greg's hack.");
  548.  
  549.     Move (0, 20);            //• Drop the pen down 20 for some "gapposis."
  550.     Center ((char*) "\pDraws various texts, centered horizontally in a window.");
  551.     Center ((char*) "\pDraws concentric ovals incrementing and decrementing in H and V.");
  552.     Center ((char*) "\pTeaches about 'for' loops, controls, drawing two things in one window, ");
  553.     Center ((char*) "\pone type of splash screen, putting \"quotes\" in coded-in text, and more.");
  554.  
  555.     TextFont (systemFont);        //• Put it back like we found it.
  556.     TextSize (12);                //• Size reverts, too.
  557.     //• Note:  Not putting this font back changed my System parameter font!
  558. }
  559.  
  560. //•-----------------------------------------------------------------------•//
  561.  
  562. MainLoop ()
  563. {
  564.     EventRecord *theEvent;
  565.     
  566.     doneFlag = false;
  567.  
  568.     do 
  569.     {
  570.     SystemTask ();
  571.     temp = GetNextEvent (everyEvent, &myEvent);
  572.     switch (myEvent.what)
  573.     {
  574.         case mouseDown:  //• mouse down, call findwindow to figure out where.
  575.             code = FindWindow (myEvent.where, &whichWindow);
  576.             switch (code)
  577.             {
  578.                 case inMenuBar:    //• in menu bar, execute the menu command. 
  579.                     HandleMenu (MenuSelect (myEvent.where));
  580.                 break;
  581.         
  582.                 case inSysWindow:    //• in desk accessory, call desk manager.
  583.                     SystemClick (&myEvent, whichWindow); 
  584.                 break;
  585.             
  586.                 case inDrag:    //• in drag, call dragWindow to move it.
  587.                     DragWindow (whichWindow, myEvent.where, &dragRect);
  588.                 break;
  589.                 
  590.                 case inContent:    //• in content area, make application window the frontmost.
  591.                     if (whichWindow != FrontWindow ())
  592.                         SelectWindow (whichWindow);
  593.                 else 
  594.                     if (ours (whichWindow))
  595.                         DoContent(whichWindow, &myEvent);
  596.                 break;
  597.             }
  598.         break;
  599.         
  600.         case keyDown:    //• If keydown event, check for menu command key.
  601.             if (myEvent.modifiers & cmdKey)
  602.                 HandleMenu (MenuKey ((char) (myEvent.message & 0377)));
  603.         break;
  604.         
  605.         case autoKey:
  606.         break;
  607.         
  608.         case activateEvt:    //• Application window becomming active, do nothing.
  609.             if ((myEvent.modifiers & 1)&& (((WindowPtr)myEvent.message) == theWindow))
  610.             {
  611.                 DisableItem (editMenu, 0);
  612.                 EnableItem (fileMenu, 0);
  613.                 DrawMenuBar ();
  614.             }
  615.             else
  616.                 {
  617.                     EnableItem (editMenu, 0);
  618.                     DisableItem (fileMenu, 0);
  619.                     DrawMenuBar ();
  620.             }
  621.         break;
  622.         
  623.         case updateEvt:    //• Update event, update the window frame.
  624.             if (((WindowPtr)myEvent.message) == theWindow)
  625.             {
  626.                 BeginUpdate (theWindow);
  627.                 DoContent (whichWindow, &myEvent);
  628.                 ControlsDataUpdate ();
  629.                 EndUpdate (theWindow);
  630.             }
  631.         break;
  632.         }
  633.     } while (doneFlag == 0);
  634. }
  635.  
  636. //•-----------------------------------------------------------------------•//
  637.  
  638. main ()
  639. {
  640.     DoInitManagers ();    //• Hire the managers for our job, here.
  641.     SetUpMenus ();        //• Without steak and eggs.
  642.     SetUpWindow ();        //• So we have a place to do our thing.
  643.     DoSplash ();        //• Brag for 4 seconds.
  644.     MainLoop ();        //• Here we go loop-de-loop!
  645. }
  646.